// var str = '2018-01-01 00:00:00'; //字符串格式的时间类型
// var str1 = str.replace(/-/g, '/'); //'2018/01/01 00:00:00'
// var date = new Date(Date.parse(str1)); //date格式的时间类型


// var nowDate = date.addMonth(3); //date格式的时间类型

Date.prototype.addMonth = function (addMonth, lastNum) {
    var year = this.getFullYear();
    var month = this.getMonth();
    var day = this.getDate();

    

    if ((month + 1 + addMonth) > 12) {
        year = year + Math.floor(parseInt(month + 1 + addMonth) / 12);
        month = parseInt(month + 1 + addMonth) % 12 - 1;
    } else {
        month = month + addMonth
    }
    
    if (lastNum <= 3) {
        let resultDateDay = Date.getLastDay(year, month).getDate();
        day = resultDateDay - lastNum;
    }

    return new Date(year, month, day);
};
//判断当前日是否为当月的最后一天
Date.getLastDay = function (year, month) {
    let nextM = month + 1 > 11 ? 0 : month + 1
    year = month + 1 > 11 ? year + 1 : year

    let endMDate = new Date(new Date(year, nextM, 1).getTime() - 86400000)
    return endMDate
}
Date.daysInMonth = function (year, month) {
    if (month == 1) {
        if (year % 400 == 0)
            return 29;
        else
            return 28;
    }
    let m_arr = [1, 3, 5, 7, 8, 10, 12]
    if (m_arr.includes(month + 1))
        return 31
    else
        return 30


};

